package main

import (
	"gitee.com/leicc/go-app-core/logics"
	"gitee.com/leicc/go-core"
	"gitee.com/leicc/go-imsrv-app/app"
	"gitee.com/leicc/go-imsrv-app/app/logic"
	"gitee.com/leicc/go-orm"
	"gitee.com/leicc/go-orm/log"
	"github.com/gin-gonic/gin"
	"os"
)

/*****************************************************************************
	IM接入层的服务 主要实现业务接入层的处理逻辑
 *****************************************************************************/
func main()  {
	config := logic.NewConfig("")
	log.Write(-1, "env", os.Getenv("DCENV"), os.Getenv("DCSRV"))
	orm.InitDBPoolSt().LoadDbConfig(config) //配置数据库结构注册到数据库调用配置当中
	log.SetLogger(config.Logger.Init())
	logics.InitCRedis(config.Redis)
	defer func() {//资源的回收处理逻辑
		logic.DeferRelease()
	}()
	state := app.NewAgent(config.Appid) //IM的状态机
	go logic.GStore.Persist() //异步执行持久化
	logic.GMQueue.InitMsgQueue(config, app.CallbackNotify)
	coApp := core.NewApp(&config.App).RegHandler(app.Register).RegHandler(func(c *gin.Engine) {
		c.GET(config.App.ImSeg, func(c *gin.Context) {
			app.DoClientService(state, c.Writer, c.Request)
		})
	})
	coApp.Start() //启动服务
}